package org.lanqiao.tjut.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.lanqiao.tjut.bean.UsersBean;
import org.lanqiao.tjut.bean.UsersBeanTea;
import org.lanqiao.tjut.myUtils.MyUtils;
import org.lanqiao.tjut.service.ServiceFactory;

public class UserTeacherAdd extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		request.setCharacterEncoding("UTF-8");
		UsersBeanTea usersBT = new UsersBeanTea();

		usersBT.setTeanum(request.getParameter("userNum"));
		usersBT.setCouid(MyUtils.obj2Integer(request.getParameter("txtCouid")));

		usersBT.setCouname(request.getParameter("txtCouname"));
		usersBT.setCoucategory(request.getParameter("txtCoucategory"));
		usersBT.setCounatyre(request.getParameter("txtCounatyre"));
		usersBT.setCoucredit(request.getParameter("txtCoucredit"));

		usersBT.setCouii(MyUtils.obj2Integer(request.getParameter("txtCouii")));

	

		// 不存在进行 添加操作
		// 3、转发Model层进行业务逻辑处理
		int i = ServiceFactory.getUserInfoManagerTeaServiceInstance().addTeaCou(usersBT);
		// 4、根据处理结果进行view层转发，将结果显示给用户客户端
		if (i > 0) {
			List<UsersBeanTea> UsersBT = ServiceFactory.getUserInfoManagerTeaServiceInstance().getAllUsersInfo(usersBT);

			request.getSession().setAttribute("lstUsersTea", UsersBT);

			request.removeAttribute("usersB");

			request.getRequestDispatcher("logined/UserInfoManager/userTeacher.jsp").forward(request, response);
		} else {
			// 显示错误信息提示页面
			request.getSession().setAttribute("pageErrorInfo", "用户信息添加失败~~~");
			response.sendRedirect("logined/error.jsp");
		}

	}

}
